﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using MyGeneration.dOOdads;
using MethodIT.Helper;
using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.ZB
{
    public partial class MyWriteTask : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            if (!IsPostBack)
            {
                LoadMyAppraisal();
            }
        }

        private void LoadMyAppraisal()
        {
            //查该用户是否是专家用户
            //得到专家ID
            //查询评分项目列表

            string UserID = DBController.GetInstance().GetAuthenticatedUserID();
            //AP_User u = new AP_User();
            //u.LoadByPrimaryKey(UserID);
            //int UmpID = u.UmpID;


            VIEW_KP_ENTRY vwKpEntry = new VIEW_KP_ENTRY();
            //vwKpEntry.Where.UmpID.Value = UmpID;
            vwKpEntry.Where.User_ID.Value = UserID;
            //vwKpEntry.Where.KpStatus.Value = KPFacade.APPRAISAL_STATUS_OF_PENDING;
            vwKpEntry.Where.UmpType.Value = 1 ;//指标
            //增加主题或考评表验证有效性
            vwKpEntry.Where.SubjectEnable.Value = "Y";
            vwKpEntry.Where.SubjectBeginDate.Value = DateTime.Now;
            vwKpEntry.Where.SubjectBeginDate.Operator = MyGeneration.dOOdads.WhereParameter.Operand.LessThanOrEqual;
            vwKpEntry.Where.SubjectEndDate.Value = DateTime.Now;
            vwKpEntry.Where.SubjectEndDate.Operator = MyGeneration.dOOdads.WhereParameter.Operand.GreaterThanOrEqual;

            vwKpEntry.Query.AddOrderBy(VIEW_KP_ENTRY.ColumnNames.KpID, WhereParameter.Dir.ASC);
            vwKpEntry.Query.Load();

            HelperDatagrid.BindAndSort(vwKpEntry.DefaultView, dgAppraisal, VIEW_KP_ENTRY.ColumnNames.KpID, VIEW_KP_ENTRY.ColumnNames.KpID);
        }

        protected void dgAppraisal_ItemDataBound1(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //HelperDatagrid.RowClick(e, "#" , "", "");

                //Label lbDeptName = (Label)e.Item.Cells[3].FindControl("lbDeptName");
                Label lbStatus = (Label)e.Item.Cells[6].FindControl("lbStatus");
                HyperLink lnkAppraisal = (HyperLink)e.Item.Cells[7].Controls[0];

                DataRow row = ((DataRowView)e.Item.DataItem).Row;
                lbStatus.Text = KPFacade.GetStatusMessage(Int32.Parse(row[VIEW_KP_ENTRY.ColumnNames.KpStatus].ToString()));
                if (Int32.Parse(row[VIEW_KP_ENTRY.ColumnNames.KpStatus].ToString()) == KPFacade.APPRAISAL_STATUS_OF_PENDING
                    || Int32.Parse(row[VIEW_KP_ENTRY.ColumnNames.KpStatus].ToString()) == KPFacade.APPRAISAL_STATUS_OF_START)
                {
                    string SubID = e.Item.Cells[0].Text;
                    string KpID = e.Item.Cells[1].Text;
                    string UmpID = e.Item.Cells[2].Text;
                    string sUrl = String.Format("ZB/ZbFromAppraisal2.aspx?subid={0}&kpid={1}&umpid={2}", SubID, KpID, UmpID);
                    lnkAppraisal.Attributes.Add(ConstantController.JS_ONCLICK, HelperURL.GetShowWindowModalStringWithParams(sUrl, 1024, 768));
                }
                else
                {
                    lnkAppraisal.Visible = false;
                }
            }
        }
    }
}